package com.snails.mall.elasticsearch.biz.common.utils;

import org.elasticsearch.search.builder.SearchSourceBuilder;

/**
 * @author gaoxu
 * date: Created on 2021/11/9 下午1:24
 */
public class ElasticClientUtil {

    /**
     * 获取分页查询资源构建器
     *
     * @param page 页码
     * @param size 每页大小
     * @return 结果
     */
    public static SearchSourceBuilder builderPageSearchBuilder(Integer page, Integer size) {
        // 给page默认值
        if (page == null && size != null) {
            page = 1;
        }

        SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
        if (page != null && size != null) {
            sourceBuilder.from((page - 1) * size);
            sourceBuilder.size(size);
        }
        return sourceBuilder;
    }
}
